package com.yulan.Str;

import org.junit.Test;

public class strStr {
    public int strStr(String haystack, String needle) {
        int len1 = haystack.length() , len2 = needle.length();
        if(len1 == 0)
            return -1;
        if(len2 == 0)
            return 0;
        for(int i=0; i < len1 - len2 + 1; i++ ){
            if(haystack.charAt(i) == needle.charAt(0)){
                if(haystack.substring(i,i+len2).equals(needle)){
                    return i;
                }
            }
        }
        return -1;
    }

    @Test
    public void test(){
        String str1 = "hello";
        String str2 = "ll";
        System.out.println(strStr(str1,str2));
    }
}
